<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/2/19
 * Time: 14:27
 */

namespace app\domain;


use app\server\peccancyData;

class peccancyInfo{

    public function addPecInfo($res,$user_id, $car_code) {

        $res = serialize($res);
        $data = [
            'user_id' => $user_id,
            'car_code' => $car_code,
            'log_data' => $res,
            'create_time' => date('Y-m-d H:i:s', time()),
        ];
        $res1 = peccancyData::addPecInfo($data);

        $where = [
            'user_id' => $user_id,
            'car_code' => $car_code,
            'type' => 1
        ];
        $res_p = peccancyData::getUserPecDataInfo($where);
        if ($res_p) {
            $data_p = [
               "log_data" => $res,
                'update_time' => date('Y-m-d H:i:s', time())
            ];
            peccancyData::updateUserPecInfo($where, $data_p);
        } else {
            $data['type'] = 1;
            $data['update_time'] = date('Y-m-d H:i:s', time());
           peccancyData::insertPecDataInfo($data);
        }
        return $res1;
    }

    public function getUserPecInfo($user_id, $car_code) {
        $where = [
            'user_id' => $user_id,
            'car_code' => $car_code,
            'is_del' => 0
        ];
        $field = "*";
        $data = peccancyData::getUserPecInfo($where, $field);

        return $data;
    }

    /**
     * 获取用户
     * @param $user_id
     * @param $car_code
     */
    public function getUserPecDataInfo ($user_id, $car_code) {
        $where = [
            'user_id' => $user_id,
            'car_code' => $car_code,
            'type' => 1,
            'is_del' => 0
        ];
        $field = "*";
        $data = peccancyData::getUserPecDataInfo($where, $field);

        return $data;
    }

    public function updateUserPecDataInfo ($user_id, $car_code, $data) {
        $where = [
            'user_id' => $user_id,
            'car_code' => $car_code,
            'type' => 1,
            'is_del' => 0
        ];
        $field = "*";
        $data = peccancyData::getUserPecDataInfo($where, $field);

        return $data;
    }

    public function insertUserPecData($data) {

        $res = peccancyData::insertPecDataInfo($data);

        return $res;
    }

    public function getUserPecCount() {

    }

    public function updateUserPecInfo() {

    }


    public function getHighPecPlace ($loa, $lon) {


    }
}